﻿using System;
using System.IO;
using System.Text;

namespace EnglishWordsToMySQL
{
    class Program
    {
        static void Main()
        {
            using (var fileReader = new StreamReader(@"D:\WebSite\英语四级单词表.txt", Encoding.Default))
            {
                var c = 0;

                using (var wordEntities = new wordsEntities())
                {
                    string str;
                    while ((str = fileReader.ReadLine()) != null)
                    {
                        var values = str.Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (values.Length < 2)
                        {
                            continue;
                        }
                        var word = new word { wvalue = values[0], wmean = values[1] };
                        wordEntities.words.Add(word);
                        c++;
                        //if (c < 300) continue;
                        try
                        {
                            wordEntities.SaveChanges();
                            Console.WriteLine(c + "words inserted");
                        }
                        catch (Exception ex)
                        {
                            wordEntities.words.Remove(word);
                            Console.WriteLine(ex.Message + "\t" + word.wvalue);
                            //throw;
                        }
                        //c = 0;
                    }
                }
            }
        }
    }
}
